
package py.una.pol.raphapy.autoventas.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Rafael E. Benegas
 */
@Entity
@Table(name = "mercaderia")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Mercaderia.findAll", query = "SELECT m FROM Mercaderia m"),
    @NamedQuery(name = "Mercaderia.findByCodMer", query = "SELECT m FROM Mercaderia m WHERE m.codMer = :codMer"),
    @NamedQuery(name = "Mercaderia.findByDesMer", query = "SELECT m FROM Mercaderia m WHERE m.desMer = :desMer")})
public class Mercaderia implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "cod_mer")
    private BigDecimal codMer;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "des_mer")
    private String desMer;
    @JoinColumn(name = "cod_tip_pre_mer", referencedColumnName = "cod_tip_pre_mer")
    @ManyToOne(optional = false)
    private TipoPresentacionMercaderia codTipPreMer;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codMer")
    private Collection<MovimientoMercaderia> movimientoMercaderiaCollection;

    public Mercaderia() {
    }

    public Mercaderia(BigDecimal codMer) {
        this.codMer = codMer;
    }

    public Mercaderia(BigDecimal codMer, String desMer) {
        this.codMer = codMer;
        this.desMer = desMer;
    }

    public BigDecimal getCodMer() {
        return codMer;
    }

    public void setCodMer(BigDecimal codMer) {
        this.codMer = codMer;
    }

    public String getDesMer() {
        return desMer;
    }

    public void setDesMer(String desMer) {
        this.desMer = desMer;
    }

    public TipoPresentacionMercaderia getCodTipPreMer() {
        return codTipPreMer;
    }

    public void setCodTipPreMer(TipoPresentacionMercaderia codTipPreMer) {
        this.codTipPreMer = codTipPreMer;
    }

    @XmlTransient
    public Collection<MovimientoMercaderia> getMovimientoMercaderiaCollection() {
        return movimientoMercaderiaCollection;
    }

    public void setMovimientoMercaderiaCollection(Collection<MovimientoMercaderia> movimientoMercaderiaCollection) {
        this.movimientoMercaderiaCollection = movimientoMercaderiaCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codMer != null ? codMer.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        
        if (!(object instanceof Mercaderia)) {
            return false;
        }
        Mercaderia other = (Mercaderia) object;
        if ((this.codMer == null && other.codMer != null) || (this.codMer != null && !this.codMer.equals(other.codMer))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "py.una.pol.raphapy.autoventas.model.Mercaderia[ codMer=" + codMer + " ]";
    }
    
}
